import request from '@/utils/request.ts';
import { type App } from '../../types/app';

/**
 * 仪表盘数据接口返回类型
 */
export interface DashboardData {
  totalApps: number;
  appIncrease: number;
  totalUsers: number;
  userIncrease: number;
  totalDownloads: number;
  downloadIncrease: number;
  pendingAudits: number;
  topApps: App[];
}

/**
 * 获取仪表盘数据
 * @returns 仪表盘数据
 */
export function getDashboardData() {
  return request<DashboardData>({
    url: '/dashboard/data',
    method: 'get'
  });
}

/**
 * 获取下载趋势数据
 * @param timeRange 时间范围：week-本周, month-本月, year-全年
 * @returns 下载趋势数据
 */
export function getDownloadTrend(timeRange: 'week' | 'month' | 'year') {
  return request<{ date: string; count: number }[]>({
    url: '/dashboard/download-trend',
    method: 'get',
    params: { timeRange }
  });
}
